package com.huike.stock_analysis.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.huike.stock_analysis.service.OperationService;

/**
 * 
 * @author mzLEI
 * 运营能力接口
 */
@RestController
@CrossOrigin(value = "*")
@RequestMapping("/operation")
public class OperationController {
	@Autowired
	private OperationService oService;
	
	//存货周转天数+行业平均
	//Inventory turnover ratio
	@RequestMapping("/inventoryDays")
	public String inventoryRatio(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = oService.inventoryTurnoverDays(stock);
		ObjectMapper mapper = new ObjectMapper();
		
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
		
	}
	//总资产周转率+行业平均
	// total assets turnover ratio
	@RequestMapping("/totalRatio")
	public String totalRatio(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = oService.totalAssetsTurnoverRatio(stock);
		//json对象
		ObjectMapper mapper = new ObjectMapper();
		
		String result = "";
		try {
			//封装
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	//流动资金周转率
	@RequestMapping("/flowRatio")
	public String flowRatio(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = oService.flowCapitalTurnoverRatio(stock);
		//json对象
		ObjectMapper mapper = new ObjectMapper();
		
		String result = "";
		try {
			//封装
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	//固定资金周转率
	@RequestMapping("/fixRatio")
	public String fixRatio(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = oService.fixCapitalTurnoverRatio(stock);
		//json对象
		ObjectMapper mapper = new ObjectMapper();
		
		String result = "";
		try {
			//封装
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	//应收账款周转率
	@RequestMapping("/accountsReceivableRatio")
	public String accountsReceivableRatio(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = oService.accountsReceivableTurnoverRatio(stock);
		//json对象
		ObjectMapper mapper = new ObjectMapper();
		
		String result = "";
		try {
			//封装
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
				e.printStackTrace();
			}
		return result;
	}
	
	//应收账款周转率
	@RequestMapping("/cashRatio")
	public String cashRatio(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = oService.cashRatio(stock);
		//json对象
		ObjectMapper mapper = new ObjectMapper();
		
		String result = "";
		try {
			//封装
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
				e.printStackTrace();
			}
		return result;
	}
	
}
